package com.hmall.search.pojo;


import com.hmall.common.dto.Item;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.beans.BeanUtils;

import java.util.ArrayList;
import java.util.List;


@Data
@NoArgsConstructor
@AllArgsConstructor
public class itemDoc {

    private Long id;//商品id
    private String name;//商品名称
    private Long price;//价格（分）
    private String image;//商品图片
    private String category;//分类名称
    private String brand;//品牌名称
    private Integer sold;//销量
    private Integer commentCount;//评论数
    private Boolean isAD;//商品广告
    private List<String> suggestion ;//用于自动补全字段


    //这里映射成eq能用的格式
    public itemDoc(Item item) {

        //拷贝属性并且赋值，spring的工具包。属性相同就可以直接拷贝，无需单独赋值
        BeanUtils.copyProperties(item,this);
        // this.id = item.getId();
        // this.name = item.getName();
        // this.price = item.getPrice();
        // this.image = item.getImage();
        // this.category = item.getCategory();
        // this.brand = item.getBrand();
        // this.sold = item.getSold();
        // this.commentCount = item.getCommentCount();
        // this.isAD = item.getIsAD();

        //填充suggestion字段: Category,brand
        suggestion = new ArrayList<>();
        suggestion.add(item.getCategory());
        suggestion.add(item.getBrand());
    }


}
